﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GestionePolveri2.DAL;
using ControlsLib;
using BrightIdeasSoftware;
using GestionePolveriLib.Facades;
using GestionePolveriLib.BL;
using GestionePolveri2.Editors;
using GestionePolveri2.Filters;
using FrameworkLib.Filters;
using FrameworkLib.Facades.Paging;
using GestionePolveri2.Reports;
using FrameworkLib.Utilities.Export;
using System.Reflection;
using GestionePolveriLib.BL.Filters;
using FrameworkLib.Configurations.FormsConfiguration;
using FrameworkLib.Configurations.FormsConfiguration.BL;

namespace GestionePolveri2
{
    public partial class CronologiaMovimenti : CronologiaMovimentiBase
    {
        Color gruppoOrigineMovimentoColore = Color.FromArgb(253, 233, 217);
        Color gruppoPolvereVernicianteColore = Color.FromArgb(235, 241, 222);
        Color gruppoQuantitaMovimentoColore = Color.FromArgb(220, 230, 241);
        Color gruppoSituazioneLottoColore = Color.FromArgb(255, 255, 204);

        Movimento2 m_currentRowObject = null;
        string[] columnsToHide = null;

        private bool modFlag = false;
        //private MovimentiPagedFacade pf = null;
        private MovimentiFacade pf = null;

        public CronologiaMovimenti()
        {
            InitializeComponent();
        }

        public override void InitializeForm()
        {
            System.Security.Principal.IPrincipal m_operatore = System.Threading.Thread.CurrentPrincipal;
            string[] roles = System.Web.Security.Roles.GetRolesForUser(m_operatore.Identity.Name);

            SavingConfigurationBag scb = new SavingConfigurationBag();
            scb.FormName = this.Name;
            scb.RoleName = roles[0];
            this.SavingConfigurationBag = scb;

            base.InitializeForm();

            if (!this.DesignMode)
            {
                this.ShowCNFGMenu = true;

                //this.Icon = GestionePolveri2.Properties.Resources.history2;

                this.AddCustomButton("btnEsportaToExcel", "Esporta in Excel");

                //pf = new MovimentiPagedFacade(100);
                pf = new MovimentiFacade();

                this.CanModify = false;
                this.ShowOnlyCustomButton = true;

                this.ButtonClicked += new EventHandler<CustomEventArgs<Movimento>>(Anagrafica_ButtonClicked);
                this.ItemSelected += new EventHandler<CustomEventArgs<Movimento>>(Anagrafica_ItemSelected);
                this.CustomButtonClicked += new EventHandler<CustomEventArgs<Movimento>>(Anagrafica_CustomButtonClicked);

                this.objectListView1.ItemChecked += new ItemCheckedEventHandler(objectListView1_ItemChecked);
                this.objectListView1.FormatRow += new EventHandler<FormatRowEventArgs>(objectListView1_FormatRow);
                this.objectListView1.FormatCell += new EventHandler<FormatCellEventArgs>(objectListView1_FormatCell);

                this.objectListView1.CellClick += new EventHandler<CellClickEventArgs>(objectListView1_CellClick);

                this.InitializeButtonBar();

                InizializzaCampi();
            }

            //RefreshColumns();
        }

        private void InizializzaCampi()
        {
            ColoraHeaders();
            NascondiColonne();

            //this.ShowPager = true;
            //this.splitContainer1.Panel2Collapsed = true;

            //this.Pager.NumberOfPages = 501; // pf.NumberOfPages;
            //pf.Pager = this.Pager;
            //this.Pager.PageChanged += new EventHandler<NavigationEventArgs>(Pager_PageChanged);
            //this.Pager.InitializeControl();

            //pf.GetNumberOfPages();

            this.IsFiltering = true;
            this.Filter.UseDatesFilter = true;
            this.ShowFilterTracing = true;

            ManageData();
        }

        private void NascondiColonne()
        {
            //columnsToHide = new string[] { };

            OperatorePrincipal m_OperatorePrincipale = (OperatorePrincipal)System.Threading.Thread.CurrentPrincipal;
            if (m_OperatorePrincipale.IsInRole("Produzione") || m_OperatorePrincipale.IsInRole("Verniciatura"))
            {
                this.objectListView1.AllColumns.Remove(this.olvColumnPrezzoUnitario);
                this.objectListView1.AllColumns.Remove(this.olvColumnValore);
                this.objectListView1.AllColumns.Remove(this.olvColumnNumFattura);
                this.objectListView1.AllColumns.Remove(this.olvColumnDataFattura);

                this.objectListView1.RebuildColumns();

                columnsToHide = new string[] {
                                 this.olvColumnPrezzoUnitario.AspectName,
                                 this.olvColumnValore.AspectName,
                                 this.olvColumnNumFattura.AspectName,
                                 this.olvColumnDataFattura.AspectName
                };
            }
        }

        public override void OnLoadConfigurazioneMaschera()
        {
            base.OnLoadConfigurazioneMaschera();

            ////NascondiColonne();
        }

        //private void RefreshColumns()
        //{
        //    ColumnsConfigurationManager ccm = new ColumnsConfigurationManager();
        //    byte[] state = ccm.GetState(this.Name);

        //    if (state != null)
        //    {
        //        bool result = this.objectListView1.RestoreState(state);
        //    }

        //    NascondiColonne();
        //}

        private void ColoraHeaders()
        {
            HeaderFormatStyle m_gruppoOrigineMovimento = new HeaderFormatStyle();
            m_gruppoOrigineMovimento.SetBackColor(gruppoOrigineMovimentoColore);
            //m_gruppoOrigineMovimento.SetForeColor(Color.Red);
            m_gruppoOrigineMovimento.SetFont(new Font(FontFamily.GenericSerif, 8, FontStyle.Bold));

            HeaderFormatStyle m_gruppoPolvereVerniciante = new HeaderFormatStyle();
            m_gruppoPolvereVerniciante.SetBackColor(gruppoPolvereVernicianteColore);
            //m_gruppoPolvereVerniciante.SetForeColor(Color.Red);
            m_gruppoPolvereVerniciante.SetFont(new Font(FontFamily.GenericSerif, 8, FontStyle.Bold));

            HeaderFormatStyle m_gruppoQuantitaMovimento = new HeaderFormatStyle();
            m_gruppoQuantitaMovimento.SetBackColor(gruppoQuantitaMovimentoColore);
            //m_gruppoQuantitaMovimento.SetForeColor(Color.Red);
            m_gruppoQuantitaMovimento.SetFont(new Font(FontFamily.GenericSerif, 8, FontStyle.Bold));

            HeaderFormatStyle m_gruppoSituazioneLotto = new HeaderFormatStyle();
            m_gruppoSituazioneLotto.SetBackColor(gruppoSituazioneLottoColore);
            //m_gruppoSituazioneLotto.SetForeColor(Color.Red);
            m_gruppoSituazioneLotto.SetFont(new Font(FontFamily.GenericSerif, 8, FontStyle.Bold));


            this.olvColumnDataMovimento.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnCodCausale.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnCausaleScarico.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnNumDDT.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnDataDDT.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnImpianto.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnOperatore.HeaderFormatStyle = m_gruppoOrigineMovimento;
            this.olvColumnNoteMov.HeaderFormatStyle = m_gruppoOrigineMovimento;

            this.olvColumnCodicePolvere.HeaderFormatStyle = m_gruppoPolvereVerniciante;
            this.olvColumnCodLotto.HeaderFormatStyle = m_gruppoPolvereVerniciante;
            this.olvColumnFamiglia.HeaderFormatStyle = m_gruppoPolvereVerniciante;
            this.olvColumnColoriAbbinati.HeaderFormatStyle = m_gruppoPolvereVerniciante;
            this.olvColumnDescrizionePolvere.HeaderFormatStyle = m_gruppoPolvereVerniciante;
            this.olvColumnNotePol.HeaderFormatStyle = m_gruppoPolvereVerniciante;

            this.olvColumnFormato.HeaderFormatStyle = m_gruppoQuantitaMovimento;
            this.olvColumnNumScatole.HeaderFormatStyle = m_gruppoQuantitaMovimento;
            this.olvColumnQuantita.HeaderFormatStyle = m_gruppoQuantitaMovimento;

            this.olvColumnGiacenzaScatole.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnGiacenzaKg.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnDataScadenzaLotto.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnValore.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnPrezzoUnitario.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnNumFattura.HeaderFormatStyle = m_gruppoSituazioneLotto;
            this.olvColumnDataFattura.HeaderFormatStyle = m_gruppoSituazioneLotto;

            //this.olvColumnImpianto.HeaderFormatStyle = m_impiatoHFS;
        }

        public override void OnSalvaConfigurazioneMaschera()
        {
            base.OnSalvaConfigurazioneMaschera();

            byte[] data = this.objectListView1.SaveState();

            System.Security.Principal.IPrincipal m_operatore = System.Threading.Thread.CurrentPrincipal;
            string[] roles = System.Web.Security.Roles.GetRolesForUser(m_operatore.Identity.Name);

            SavingConfigurationBag scb = new SavingConfigurationBag();
            scb.FormName = this.Name;
            scb.RoleName = roles[0];
                       
            ColumnsConfigurationManager ccm = new ColumnsConfigurationManager();
            ccm.Configuration = scb;
            ccm.State = data;
            ccm.SaveState();
        }

        public override void OnRipristinaConfigurazioneDefaultMaschera()
        {
            base.OnRipristinaConfigurazioneDefaultMaschera();

            NascondiColonne();
        }

        public override void OnFilterExecuted()
        {
            base.OnFilterExecuted();

            this.IsFiltering = true;

            //pf.GetNumberOfPages(this.Filter.FilterBag);

            ManageData();
        }

        public override void OnFilterReset()
        {
            //this.IsFiltering = false;
            this.IsFiltering = true;

            base.OnFilterReset();

            //pf.GetNumberOfPages();

            ManageData();
        }

        public override void OnRefreshFilterData()
        {
            base.OnRefreshFilterData();

            ManageData();
        }

        void editor_LoadData(object sender, EventArgs e)
        {
            ManageData();
        }

        //private void ManageData()
        //{
        //    if (!this.IsFiltering)
        //    {
        //        LoadData(false);
        //    }
        //    else
        //    {
        //        LoadData(this.Filter.FilterBag);
        //    }
        //}

        void objectListView1_CellClick(object sender, CellClickEventArgs e)
        {
            if (e.Item == null) return;

            if (e.ClickCount == 2)
            {
                OperatorePrincipal m_OperatorePrincipale = (OperatorePrincipal)System.Threading.Thread.CurrentPrincipal;
                if (m_OperatorePrincipale.IsInRole("Amministrazione") || m_OperatorePrincipale.IsInRole("Verniciatura"))
                {
                    Font m_font = this.objectListView1.Items[e.RowIndex].Font;

                    this.objectListView1.Items[e.RowIndex].Font = new System.Drawing.Font(FontFamily.GenericSerif, 10, FontStyle.Bold);

                    m_currentRowObject = (Movimento2)e.Item.RowObject;

                    if (m_currentRowObject.CodCausale == "C")
                    {
                        GestionePolveri2.Editors.CaricoEditor ce = new GestionePolveri2.Editors.CaricoEditor();
                        ce.LoadData += new EventHandler(editor_LoadData);
                        ce.Movimento = m_currentRowObject;
                        ce.EditorStatus = EditorStatus.Modifiy;
                        ce.Principal = (OperatorePrincipal)this.Principal;
                        ce.Funtion = "C";

                        if (ce.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            Movimento2 m_movimento = (Movimento2)ce.Movimento;
                        }

                        this.objectListView1.Items[e.RowIndex].Font = m_font;
                    }

                    if (m_currentRowObject.CodCausale == "S")
                    {
                        GestionePolveri2.Editors.ScaricoEditor se = new GestionePolveri2.Editors.ScaricoEditor();
                        se.LoadData += new EventHandler(editor_LoadData);
                        se.Movimento = m_currentRowObject;
                        se.EditorStatus = EditorStatus.Modifiy;
                        se.Principal = (OperatorePrincipal)this.Principal;
                        se.Funtion = "C";

                        if (se.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            Movimento2 m_movimento = (Movimento2)se.Movimento;
                        }

                        this.objectListView1.Items[e.RowIndex].Font = m_font;
                    }
                }
                else
                    MessageBox.Show("Funzione non abilitata !");
            }
        }

        void objectListView1_FormatRow(object sender, FormatRowEventArgs e)
        {
            Color m_color = this.objectListView1.BackColor;

            Movimento2 movimento = (Movimento2)e.Model;
            if (modFlag == true)
            {
                m_color = Color.Green;

                e.Item.ForeColor = Color.Green;
                modFlag = false;
            }
            else
                e.Item.ForeColor = Color.Black;


            if (movimento.SottoScortaFlag)
            {
                m_color = Color.Red;
            }

            if (movimento.GiacenzaInsufficienteFlag)
            {
                m_color = Color.Yellow;
            }

            //this.objectListView1.Items[e.RowIndex].BackColor = m_color;
           
        }

        private void objectListView1_FormatCell(object sender, FormatCellEventArgs e)
        {
            switch (e.ColumnIndex)
            {
                case 0:
                    {
                        e.Item.BackColor = e.Column.HeaderFormatStyle.Normal.BackColor;
                    }
                    break;
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                    {
                        //e.Item.BackColor = e.Column.HeaderFormatStyle.Normal.BackColor;
                        e.SubItem.BackColor = e.Column.HeaderFormatStyle.Normal.BackColor;
                    }
                    break;
                default:
                    e.SubItem.BackColor = e.Column.HeaderFormatStyle.Normal.BackColor;
                    break;
            }

            Movimento2 mov = (Movimento2)e.Model;

            if (e.ColumnIndex == this.olvColumnGiacenzaScatole.Index)
            {
                if (mov.GiacenzaInsufficienteFlag)
                {
                    e.SubItem.ForeColor = Color.Red;
                    e.SubItem.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
                    e.SubItem.Decoration = new ImageDecoration(GestionePolveri2.Properties.Resources.flag_red, 100);
                }

                if (mov.SottoScortaFlag)
                {
                    e.SubItem.ForeColor = Color.Red;
                    e.SubItem.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
                    e.SubItem.Decoration = new ImageDecoration(GestionePolveri2.Properties.Resources.flag_red, 100);
                }
            }

            if (e.ColumnIndex == this.olvColumnGiacenzaKg.Index)
            {
                if (mov.GiacenzaInsufficienteFlag)
                {
                    e.SubItem.ForeColor = Color.Red;
                    e.SubItem.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
                    e.SubItem.Decoration = new ImageDecoration(GestionePolveri2.Properties.Resources.flag_red, 100);
                }

                if (mov.SottoScortaFlag)
                {
                    e.SubItem.ForeColor = Color.Red;
                    e.SubItem.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Bold);
                    e.SubItem.Decoration = new ImageDecoration(GestionePolveri2.Properties.Resources.flag_red, 100);
                }
            }

            
        }

        private List<Movimento2> GetDataToExport()
        {
            List<Movimento2> retValue = null;

            MovimentiFacade pf = new MovimentiFacade();
            retValue = (this.IsFiltering ? pf.GetMovimenti(this.Filter.FilterBag) : pf.GetMovimenti());

            return retValue;
        }

        void Anagrafica_CustomButtonClicked(object sender, CustomEventArgs<Movimento> e)
        {
            if (e.ButtonName.Equals("btnEsportaToExcel", StringComparison.InvariantCultureIgnoreCase))
            {
                //MovimentiFacade pf = new MovimentiFacade();
                pf.RunAsync(() => GetDataToExport(), (result) =>  //   () => pf.GetMovimenti(), (result) =>
                {
                    if (result != null)
                    {
                        //string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                        //string filename = string.Format(@"{0}\Prova.xls", path);

                        SaveFileDialog sfd = new SaveFileDialog();
                        sfd.Filter = "Excel Files (.xls)|*.xls|All Files (*.*)|*.*";
                        sfd.FilterIndex = 1;
                        if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            string errorMessage = string.Empty;
                            if (((List<Movimento2>)result).ToExcel(sfd.FileName, out errorMessage, columnsToHide))
                            {
                                MessageBox.Show("Esportazione in Excel effettuata!", "Gestione Polveri", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show(string.Format("ATTENZIONE: Si è verificato un errore: {0}", errorMessage), "Gestione Polveri", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Nessun dato da inviare in stampa.", "Gestione Polveri", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                });
            }
        }

        void Anagrafica_ButtonClicked(object sender, CustomEventArgs<Movimento> e)
        {
            switch (e.Action)
            {
                case Actions.New:
                    {
                    }
                    break;
                case Actions.Add:
                    {
                    }
                    break;
                case Actions.Modify:
                    {
                    }
                    break;
                case Actions.Delete:
                    {
                    }
                    break;
                case Actions.Cancel:
                    {
                        //Pager_PageChanged(this, new NavigationEventArgs(NavigationEventType.First));
                    }
                    break;
                default:
                    break;
            }
        }

        void Anagrafica_ItemSelected(object sender, CustomEventArgs<Movimento> e)
        {
            base.Current = e.Item;
        }

        void objectListView1_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            Movimento m_movimento = ((Movimento)((OLVListItem)e.Item).RowObject);
        }

        //void Pager_PageChanged(object sender, NavigationEventArgs e)
        //{
        //    if (e.Position < 0)
        //    {
        //        MessageBox.Show("Valore negativo come indice di navigazione non permesso!", "Gestione Polveri", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        //        return; 
        //    };

        //    switch (e.NavigationEventType)
        //    {
        //        case NavigationEventType.First:
        //            pf.First();
        //            break;
        //        case NavigationEventType.Next:
        //            pf.Next();
        //            break;
        //        case NavigationEventType.Previous:
        //            pf.Previous();
        //            break;
        //        case NavigationEventType.Last:
        //            pf.Last();
        //            break;
        //        case NavigationEventType.GotToPosition:
        //            pf.PageNumber = e.Position;
        //            break;
        //        default:
        //            break;
        //    }

        //    ManageData();
        //}

        protected override void LoadData()
        {
            SplashPage sp = new SplashPage();
            sp.ShowDialog();

            base.LoadData();

            //MovimentiFacade pf = new MovimentiFacade();

            pf.RunAsync<List<Movimento2>>(() => pf.GetMovimenti(), (result) =>
            //pf.LoadAsync((result) =>
            {
                

                if (result != null)
                {
                    //this.Pager.NumberOfPages = pf.NumberOfPages;

                    this.objectListView1.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
                    this.objectListView1.SetObjects((List<Movimento2>)result, true);

                    sp.Close();
                    //double m_totCarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "C").Sum(x => x.Quantita);
                    //double m_totScarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "S").Sum(x => x.Quantita);

                    //this.lblTotCarico.Text = m_totCarico.ToString();
                    //this.lblTotScarico.Text = m_totScarico.ToString();

                    double m_totCarichi = pf.GetTotaleMovimenti("C");
                    double m_totScarichi = pf.GetTotaleMovimenti("S");
                    
                    this.lblTotCarico.Text = string.Format("Kg {0:N}", m_totCarichi);
                    this.lblTotScarico.Text = string.Format("Kg {0:N}", m_totScarichi);
                    this.lblTotGiacenza.Text = string.Format("Kg {0:N}", m_totCarichi - m_totScarichi);                   
 
                }
                else
                {
                    this.objectListView1.EmptyListMsg = "Nessun movimento trovato";
                    ClearTotali();
                    // this.objectListView1.EmptyListMsgFont = new Font("Tahoma", 24);                    
                }                

            });
        }

        protected override void LoadData(CronologiaFilterBag filter)
        {
            SplashPage sp = new SplashPage();
            sp.ShowDialog();

            base.LoadData(filter);

            pf.RunAsync<List<Movimento2>>(() => pf.GetMovimenti(filter), (result) =>
            {
                this.objectListView1.Items.Clear();
                if (result != null)
                {
                    this.objectListView1.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
                    this.objectListView1.SetObjects((List<Movimento2>)result, true);

                    double m_totCarichi = ((List<Movimento2>)result).Where(x => x.CodCausale == "C").Sum(x => x.Quantita);
                    double m_totScarichi = ((List<Movimento2>)result).Where(x => x.CodCausale == "S").Sum(x => x.Quantita);

                    //this.lblTotCarico.Text = m_totCarico.ToString();
                    //this.lblTotScarico.Text = m_totScarico.ToString();

                    this.lblTotCarico.Text = string.Format("Kg {0:N}", m_totCarichi);
                    this.lblTotScarico.Text = string.Format("Kg {0:N}", m_totScarichi);
                    this.lblTotGiacenza.Text = string.Format("Kg {0:N}", m_totCarichi - m_totScarichi);

                    sp.Close();
                }
                else
                {
                    this.objectListView1.EmptyListMsg = "Nessun movimento trovato";
                    ClearTotali();
                }
            });



            //List<Movimento2> result = GetDataByFilter(filter);

            //this.objectListView1.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
            //this.objectListView1.SetObjects((List<Movimento2>)result, true);

            #region
            //double m_totCarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "C").Sum(x => x.Quantita);
            //double m_totScarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "S").Sum(x => x.Quantita);

            //this.lblTotCarico.Text = m_totCarico.ToString();
            //this.lblTotScarico.Text = m_totScarico.ToString();

            //pf.RunAsync<Movimenti>(() => GetDataByFilter(m_filter), (result) =>
            //{
            //    if (result != null)
            //    {
            //        this.objectListView1.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
            //        this.objectListView1.SetObjects((List<Movimento2>)result, true);

            //        double m_totCarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "C").Sum(x => x.Quantita);
            //        double m_totScarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "S").Sum(x => x.Quantita);

            //        this.lblTotCarico.Text = m_totCarico.ToString();
            //        this.lblTotScarico.Text = m_totScarico.ToString();
            //    }
            //});

            //pf.LoadAsync((result) =>
            //{
            //    if (result != null)
            //    {
            //        this.objectListView1.AddDecoration(new EditingCellBorderDecoration { UseLightbox = true });
            //        this.objectListView1.SetObjects((List<Movimento2>)result, true);

            //        double m_totCarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "C").Sum(x => x.Quantita);
            //        double m_totScarico = ((List<Movimento2>)result).Where(x => x.CodCausale == "S").Sum(x => x.Quantita);

            //        this.lblTotCarico.Text = m_totCarico.ToString();
            //        this.lblTotScarico.Text = m_totScarico.ToString();
            //    }
            //});
            #endregion
        }

        private void objectListView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.objectListView1.SelectedItem != null)
                m_currentRowObject = (Movimento2)this.objectListView1.SelectedItem.RowObject;
        }

        private void ClearTotali()
        {
            this.lblTotCarico.Text = string.Empty;
            this.lblTotScarico.Text = string.Empty;
        }
    }

    public class CronologiaMovimentiBase : AnagraficaManagerFilteredObjectListView<Movimento, CronologiaFilter2, CronologiaFilterBag> { }

    //public class CronologiaMovimentiBase : AnagraficaManagerObjectListView<Movimento> { }
}
